import { Transform, TransformFnParams } from 'class-transformer';
import {
  Entity,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  DeleteDateColumn,
  Column,
} from 'typeorm';

@Entity('user_token')
export class UserTokenEntity {
  @PrimaryGeneratedColumn({
    type: 'bigint',
    name: 'user_token_id',
    comment: '主键id',
  })
  user_token_id: number;

  @Column({
    type: 'int',
    nullable: false,
    unique: true,
    name: 'user_id',
    comment: '关联用户表的id',
  })
  user_id: number;

  @Column({
    type: 'varchar',
    nullable: false,
    length: 100,
    unique: true,
    name: 'token',
    comment: 'token',
  })
  token: string;

  @Column({
    type: 'varchar',
    nullable: false,
    length: 45,
    name: 'username',
    comment: '用户名',
  })
  username: string;

  @Column({
    type: 'varchar',
    nullable: true,
    length: 11,
    name: 'mobile',
    comment: '手机号码',
  })
  mobile: string;

  @Column({
    type: 'tinyint',
    nullable: false,
    default: 0,
    name: 'is_super',
    comment: '是否为超级管理员1表示是,0表示不是',
  })
  isSuper: number;

  @Column({
    type: 'timestamp',
    name: 'expire_time',
    nullable: true,
    comment: '失效时间',
  })
  expireTime: Date;

  @Transform((row: TransformFnParams) => +new Date(row.value))
  @CreateDateColumn({
    type: 'timestamp',
    nullable: false,
    name: 'created_at',
    comment: '创建时间',
  })
  createdAt: Date;

  @Transform((row: TransformFnParams) => +new Date(row.value))
  @UpdateDateColumn({
    type: 'timestamp',
    nullable: false,
    name: 'updated_at',
    comment: '更新时间',
  })
  updatedAt: Date;
}
